package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.Menu;
import com.xrit.sunnyday.pojo.Role;
import com.xrit.sunnyday.pojo.UserInfo;
import com.xrit.sunnyday.service.MenuService;
import com.xrit.sunnyday.service.UserService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Set;

/**
 * 类名称: MenuController
 * 类描述:TODO
 * 创建人: czb
 * 创建时间:2022/7/13 下午 03:27
 * Version 1.0.0
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    @Reference
    private MenuService menuService;
    @Reference
    private UserService userService;

    @GetMapping("/getMenu")
    public Result getMenu(){
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        UserInfo userInfo = userService.findByUserName(name);
        Set<Role> roles = userInfo.getRoles();
        List<Menu> list=null;
        for (Role role : roles) {
            list = menuService.getMenu(role.getId());
        }
        return new Result(true, MessageConstant.GET_MENU_SUCCESS,list);
    }
}
